package org.dru.clay.respository;

import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;

import org.dru.clay.respository.artifact.Artifact;
import org.dru.clay.respository.ivy.IvyVisibility;

public class Configuration implements Comparable<Configuration> {
	private final Set<Artifact> artifacts = new TreeSet<Artifact>();

	private final String name;
	private final String description;
	private final IvyVisibility visibility;

	public Configuration(String name, String description, IvyVisibility visibility) {
		this.name = name;
		this.description = description;
		this.visibility = visibility;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public IvyVisibility getVisibility() {
		return visibility;
	}

	public void addArtifact(Artifact artifact) {
		artifacts.add(artifact);
	}

	public Collection<Artifact> getArtifacts() {
		return artifacts;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((visibility == null) ? 0 : visibility.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Configuration other = (Configuration) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (visibility != other.visibility)
			return false;
		return true;
	}

	@Override
	public int compareTo(Configuration o) {
		return name.compareToIgnoreCase(o.name);
	}

	public String toString() {
		final StringBuilder builder = new StringBuilder();
		builder.append(name).append("{ artifacts: ").append(artifacts).append("}");
		return builder.toString();
	}
}
